﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using XWord.Fundamental.Domain;
using XWord.Fundamental.Data.Impl;

namespace XWord.GUI.Views
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class EtymonEditView : Window
    {
        public EtymonEditView()
        {
            InitializeComponent();
           
        }

        public bool IsEdit { get; set; }

        public Etymon EditEtyma { get; set; }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            EtymaRepository rep = new EtymaRepository();
            if (!IsEdit)
            {

                Etymon ety = new Etymon();
                ety.Name = textBox1.Text;
                ety.Comment = textBox2.Text;
               
                if (EditEtyma != null)
                {
                  
                    //ety.ParentId = EditEtyma.Id;
                    EditEtyma.Children.Add(ety);
                }
                rep.MakePersistent(ety);
                UnitOfWork.CurrentSession.Flush();
                if (EditEtyma != null)
                {
                    ety.Parent = EditEtyma;
                   
                }
               // MessageBox.Show("成功");
                this.Close();
            }
            else
            {
                Etyma ety =rep.Get(EditEtyma.Id);
                ety.Name = textBox1.Text;
                ety.Comment = textBox2.Text;
                rep.MakePersistent(ety);
                UnitOfWork.CurrentSession.Flush();
               // MessageBox.Show("成功");
                this.Close();
            }        }
    }
}
